package serviceImpl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import dao.DepartmentDao;
import daoImpl.DepartmentDaoImpl;
import entity.Department;
import service.DepartmentService;
import utils.JdbcUtils;

public class DepartmentServiceImpl implements DepartmentService {

	DepartmentDao departmentDao=new DepartmentDaoImpl();
	
	public List<Department> getDepartmentList() {
		
		Connection connection=null;
		
		try {
			connection=JdbcUtils.getConnection();
			connection.setAutoCommit(false);
			String sql="select dept_id as deptId,dept_name as deptName from department";
			List<Department> list = departmentDao.getDepartmentList(connection, sql, Department.class);
			connection.commit();
			return list;
		} catch (SQLException e) {
			if(connection!=null) {
				try {
					connection.rollback();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
					
			e.printStackTrace();
		}finally {
			JdbcUtils.close();
		}
	
		return null;
	}

}
